React = require('react')
{connect} = require('react-redux')
{View,InteractionManager,Text,Image,TextInput,TouchableOpacity} = require('react-native')
# Flex = require('antd-mobile/lib/flex')
Button = require('antd-mobile/lib/button')
Dimensions = require('Dimensions')
{ width, height } = Dimensions.get('window')
backImg = require('../img/back.png')

Toast = require('antd-mobile/lib/toast')
{logOut,fetchLogin,fetchLogOut} = require('../actions/userInfo.js')
# {fetchGetMenu} = require('../actions/menuInfo.js')
page_changePass = require('./page_changePass.js')
Setting = React.createClass
  clickHandle:->
    debugger
    @setState clicked:true
    @props.dispatch fetchLogin
      name:@state.name
      pass:@state.pass
  changePassHandle:->
    {navigator} = @props
    navigator.push
      name:'changePass'
      component:page_changePass
      title:'修改密码'
  exitHandle:->
    that = @
    Toast.success('登陆已退出',1)
    that.props.navigator.pop()
    InteractionManager.runAfterInteractions =>
      # that.props.scrollToTop()
      that.props.dispatch fetchLogOut()
      # that.props.dispatch logOut()
      # that.props.dispatch fetchLogin(name:'guest',pass:'')

  # componentDidUpdate:->
  #   that = @
  #   if @state.clicked and  @props.userInfo.pilotCode and @props.userInfo.pilotCode isnt 'guest'
  #     Toast.info('登陆成功')
  #     setTimeout ->
  #       that.props.navigator.pop()
  #     ,1000
  render:->
    # flexDirection:'column',alignItems:'center'
      <View style={{height:height,width:width,backgroundColor:'#ffffff'}}>
        <View style={{flexDirection:'row',flex:0,height:60,alignItems:'center', justifyContent:'center',backgroundColor:'#0066FF'}}>
          <View style={{flex:1,padding:10}}>
            <TouchableOpacity onPress={=>@props.navigator.pop()}>
              <Image source={backImg}  style={{height:30,width:30,resizeMode:'contain'}}/>
            </TouchableOpacity>
          </View>
          <View style={{flex:1,justifyContent:'center',alignItems:'center'}}>
            <Text style={{fontSize:20,color:'#ffffff'}}>设置</Text>
          </View>

          <View style={{flex:1,alignItems:'flex-end',padding:10}}>
            <TouchableOpacity onPress={@_showActionSheet}>
            </TouchableOpacity>
          </View>
        </View>
        {
          do =>
            if @props.userInfo.pilotCode not in ['guest','',null]
              [<View key='1' style={{margin:10}}>
                <Button type='warning' onClick={@exitHandle}>退出登陆</Button>
              </View>
              <View key='2' style={{margin:10}}>
                <Button type='primary' onClick={@changePassHandle}>修改密码</Button>
              </View>]
        }
        <View style={{margin:10}}>
          <Text>当前版本:{@props.version}</Text>
        </View>
      </View>

mapStateToProps = (state)->
  userInfo:state.userInfo
  version:state.appState.version
module.exports = connect(mapStateToProps)(Setting)
